<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>代看课详情-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart style="background-color: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left">
	  		 <a href="<%=basePath %>/ls/teacher/replace/course" href="javascript:;" class="icon icon-109 f-white">返回</a > 
	  		</div>
	    	<h1 class="weui-header-title">${detail.optionTypeText }详情</h1>
	    </div>
		<div class="weui_tab_bd" style="padding-bottom: 95px;">
			<div class="weui_panel_bd">
                <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">
                    <div class="weui_media_hd">
                        <img style="border-radius: 100%;" class="weui_media_appmsg_thumb" src="${config.imgUrl }${detail.headImgUrl}" alt="">
                    </div>
                    <div class="weui_media_bd">
                        <h4 class="weui_media_title">${detail.applyTeacherName }</h4>
                        <p class="weui_media_desc f-orange">${detail.nextStatusText }</p>
                    </div>
                </a>
			</div>
			
			<div class="weui_cells mt0">
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">班级：</span>${detail.gradeName }（${detail.clazz }）班
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">代看课类型：</span>${detail.optionTypeText }
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">课程：</span>${detail.subjectName }
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">授课教师：</span>${detail.applyTeacherName }
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">事由：</span>${detail.reason }
					</div>
				</div>
			</div>
			<div class="weui_cells mt0">
				<div class="weui_cell xtbg-add-list-title">
					<div class="weui_cell_bd weui_cell_primary">
						<p class="f14">${detail.optionTypeText }对象</p>
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">时间：</span> <fmt:formatDate type="date" value="${detail.courseDate }" />
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">节次：</span>${detail.lesson }
					</div>
				</div>
				<div class="weui_cell">
					<div class="weui_cell_bd weui_cell_primary">
						<span class="f-graybc">是否有${detail.optionTypeText }教师：</span>
						<c:if test="${detail.isReplaceTeacher == 1}">有</c:if>
						<c:if test="${detail.isReplaceTeacher == 0}">没有</c:if>
					</div>
				</div>
				<c:choose>
					<c:when test="${detail.isReplaceTeacher == 1 || detail.replaceTeacherId != null}">
						<div class="weui_cell">
							<div class="weui_cell_bd weui_cell_primary">
								<span class="f-graybc">${detail.optionTypeText }教师：</span>${detail.replaceTeacherName }
								<c:if test="${detail.isReplaceTeacher == 0}">
									<span class="f-red">（由教务处指派）</span>
								</c:if>
							</div>
						</div>
					</c:when>
					<c:otherwise>
						<div class="weui_cell weui_cell_select">
							<div class="weui_cell_hd">
								<span class="f-graybc pl15">${detail.optionTypeText }教师：</span>
							</div>
							<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
			                	<div class="searchbar_wrap"></div>
								<div id="search-content" style="height: 100%;z-index: 10;display:none;">
							       <div class="sb-content" style="position:inherit;overflow:scroll;">
							       </div>
							    </div>
							    <input type="hidden" name="replaceTeacherId"/>
							    <input type="hidden" name="replaceTeacherName"/>
			                </div>
						</div>
					</c:otherwise>
				</c:choose>
			</div>
			<div class="weui_cells mt0">
				<div class="timeline">
				  	<ul>
				  		<c:forEach var="item" items="${detail.reqList }" varStatus="stat">
				  			<li class="timeline-item"> 
					   			<c:choose>
					   				<c:when test="${item.status == '000' || item.status == '002'}">
					   					<div class="timeline-item-head-first"> 
							  				<i class="weui_icon weui_icon_success_no_circle timeline-item-checked"></i> 
							  			</div> 
					   				</c:when>
					   				<c:when test="${item.status == '001' }">
					   					<div class=""> 
							   				<img class="gzsp-timeline-flow-img" src="<%=basePath %>/images/wait_icno.png">
							   			</div> 
					   				</c:when>
					   				<c:when test="${item.status == '003' || item.status == '004' || item.status == '005'}">
					   					<div class=""> 
							   				<img class="gzsp-timeline-flow-img" src="<%=basePath %>/images/bohuishenqing@3x.png">
							   			</div> 
					   				</c:when>
					   			</c:choose>
					   			<c:if test="${!stat.last}">
					   				<div class="timeline-item-tail" style="top: 25px;"></div> 
					   			</c:if>
					   			<div class="timeline-item-content">
					   				<div class="weui_panel_bd gzsp-timeline-flow">
						                <a href="javascript:void(0);" class="weui_media_box weui_media_appmsg">
						                    <div class="weui_media_hd">
						                        <img style="border-radius: 100%;" class="weui_media_appmsg_thumb" src="${config.imgUrl }${item.headImgUrl}" alt="">
						                    </div>
						                    <div class="weui_media_bd">
						                        <h4 class="weui_media_title">${item.teacherName }</h4>
						                        <p class="weui_media_desc">
						                        	<c:if test="${item.status == '000' || item.status == '002'}"><span class="f-green">${item.statusText }</span></c:if>
	                        						<c:if test="${item.status == '001' }"><span class="f-yellow2">发起申请</span></c:if>
	                        						<c:if test="${item.status == '003' || item.status == '004' || item.status == '005' }"><span class="f-red">${item.statusText }</span></c:if>
						                        </p>
						                        <c:if test="${item.status == '003' || item.status == '004'}">
						                        	<p class="weui_media_desc">驳回原因：${item.rejectReason }</p>
						                        </c:if>
						                    </div>
						                </a>
									</div>
					   			</div> 
					   		</li>
				  		</c:forEach>
				     </ul> 
				</div>
			</div>
		</div>
	</div>
	<c:if test="${approverType > 0}">
		<c:choose>
			<c:when test="${detail.status == '000' }">
				<section class="weui-menu">
			        <div class="weui-menu-inner" id="cancelSubmit">
			            <span>撤销</span>
			        </div>
			    </section>
			</c:when>
			<c:otherwise>
				<section class="weui-menu">
			        <div class="weui-menu-inner" id="rejectSubmit">
			            <span>驳回</span>
			        </div>
			        <div class="weui-menu-inner" id="agreeSubmit">
			            <span>同意</span>
			        </div>
			    </section>
			</c:otherwise>
		</c:choose>
	    
	    <!--弹窗-->				
		<div class="weui_mask ueureiu weui_mask_visible" style="display: none;z-index:600">
		</div>
		<!--End弹窗-->
		<div class="weui_dialog weui_dialog_visible" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);display:none;z-index:700;">
			<div class="weui_dialog_hd">
				<strong class="weui_dialog_title">请输入驳回原因</strong>
			</div>
			<div class="weui_dialog_bd">
				<textarea class="weui-prompt-input" style="height: 80px;width: 95%;" rows="10" id="rejectText"></textarea>
			</div>
			<div class="weui_dialog_ft">
				<a href="javascript:;" id="rejectCancel" class="weui_btn_dialog default">取消</a>
				<a href="javascript:;" id="rejectSure" class="weui_btn_dialog primary">确定</a>
			</div>
		</div>
		<script>
			$(function() {
				$('.searchbar_wrap').searchBar({
					cancelText: "取消",
					searchText: '请输入教师姓名',
					onfocus: function(value) {
						$("#search-content").show();
						$(".weui_panel").hide();
					},
					onblur: function(value) {
					},
					input: function(value) {
						queryTeacherItem(value);
					},
					onsubmit: function(value) {
						queryTeacherItem(value);
					},
					oncancel: function() {
						$("#search-content").hide();
						$(".sb-content").html('');
						$("input[name='replaceTeacherId']").val(null);
						$("input[name='replaceTeacherName']").val(null);
					},
					onclear: function() {
						$("#search-content").hide();
						$(".sb-content").html('');
						$("input[name='replaceTeacherId']").val(null);
						$("input[name='replaceTeacherName']").val(null);
					}
			    });
			  	$("#teacherSure").click(function() {
		      		$('.ueureiu').hide();
					$("#ls_div_box").hide();
					var list = $("#teacherList").find(".list_c3 input:checked");
					if(list.length == 0){
						$(".gzsp_wrap>ul").html("");
					}else {
						var html = "";
						list.each(function(i, e){
							var obj = $(e);
							var name = obj.closest(".list_c3").find(".tea_name").html();
							html += "<li><div class='gzsp'><span>"+name.substr(name.length-2,name.length)+"</span><i data-id='"+obj.val()+"'>"+name+"</i></div></li>";
						})
						$(".gzsp_wrap>ul").html(html);
					}
		      	})
		      	$("#agreeSubmit").click(function() {
		      		$.confirm("您确定审批通过吗?","", function() {
		      			agreeSubmit();
		            }, function() {
		                //取消操作
		            });
		      	})
		      	$("#cancelSubmit").click(function() {
		      		$.confirm("您确定撤销申请吗?","", function() {
		      			var params = {
      		  				id: "${detail.id}",
      		      			prevStatus: "${detail.status}",
      		      			status: "005"
      		      		}
      		      		replySubmit(params);
		            }, function() {
		                //取消操作
		            });
		      	})
		      	$("#rejectSubmit").click(function() {
	      			$(".weui_mask").addClass("weui_mask_visible").show();
	      			$(".weui_dialog").addClass("weui_dialog_visible").show();
	      			$("#rejectCancel").click(function(){
	      				$("#rejectText").val(null);
	      				$(".weui_mask").hide();
	      				$(".weui_dialog").hide();
	      			});
	      			$("#rejectSure").click(function(){
	      				var text = $("#rejectText").val();
	      				if(text.trim().length > 0) {
	      		      		var params = {
	      		  				id: "${detail.id}",
	      		      			rejectReason: text,
	      		      			prevStatus: "${detail.status}",
	      		      			status: "${approverType}" == "1" ? "003" : "004"
	      		      		}
	      		      		replySubmit(params);
		      		      	$(".weui_mask").hide();
		      				$(".weui_dialog").hide();
		      				$("#rejectText").val(null);
	      		      	}
	      			});
		      	})
			});
			function replySubmit(params) {
				$.ajax({
		          	url : basePath + "/ls/teacher/replace/course/audit/reject",
		  	 		type : "post",
		  	 		dataType : "json",
		  	 		data : params,
		            success: function(data){
		            	if(data.code == '000') {
		            		$.toast("提交成功！");
		            		setTimeout(function() {
		            			window.location.reload();
		            		}, 1000);
		            		return;
		            	}
		            	$.toptips(data.msg);
		            },
		            error: function(xhr, type){
		            	$.toptips("系统异常");
		            }
		         });
			}
			function agreeSubmit() {
				var param = {
					id: "${detail.id}"
				};
				if("${detail.isReplaceTeacher}" == '0') {
					var replaceTeacherId = $("input[name='replaceTeacherId']").val();
					var replaceTeacherName = $("input[name='replaceTeacherName']").val();
					if(replaceTeacherId.length == 0) {
						$.alert("未指定${detail.optionTypeText}教师！","");
						return;
					}
					param.replaceTeacherId = replaceTeacherId;
					param.replaceTeacherName = replaceTeacherName;
				}
				param.status = "${approverType}" == "1" ? "002" : "000";
				param.prevStatus = "${detail.status}";
				$.ajax({
					url: basePath + '/ls/teacher/replace/course/audit/success',
					type: 'post',
					dataType: 'json',
					data: param,
					success: function(data) {
						if(data.code == '000') {
							$.toast("提交成功");
							setTimeout(function() {
		            			window.location.reload();
		            		}, 1000);
						}else {
							$.toptips(data.msg);
						}
					},
		            error: function(xhr, type){
		            	$.toptips("系统异常");
		            }
				});
			}
			var search = false;
			function queryTeacherItem(keyword) {
				if(keyword != null) {
					if(!/^[\u4E00-\u9FA5]+$/.test(keyword)) return;
					if(search) return;
					search = true;
				}
				$.ajax({
					url: basePath + "/ls/teacher/manage/keyword",
					type: 'POST',
					dataType : "json",
					data: {
						teacherName: keyword
					},
					success: function(data) {
						search = false;
						var html = "";
						if (data != null && data.length > 0) {
							for(var i in data) {
								var itm = data[i];
								html += '<div class="weui_cell"><p onclick=choseStudent('+itm.id+',"'+itm.name+'")>'+ itm.name + '</p></div>';
							}
						}
						$(".sb-content").html(html);
					},
					error: function(data) {
						alert("系统异常,请联系管理员");
					}
				})
			}
			function choseStudent(studentId, studentName) {
				$("#weui_search_input").val(studentName);
				$(".sb-content").html('');
				$("#search-content").hide();
				$("input[name='replaceTeacherId']").val(studentId);
				$("input[name='replaceTeacherName']").val(studentName);
			}
		</script>
	</c:if>
	<c:if test="${approverType == 0}">
		<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
	</c:if>
</body>
<script>
	
	
</script>
</html>